<template>
    <div class="Child">
        <h2>子组件2</h2>
        <h3>电脑：{{ computer }}</h3>
        <h3 v-show="toy">子组件1给的玩具：{{ toy }}</h3>
    </div>
</template>

<script lang="ts" setup name="Child2">
    import {ref,onUnmounted} from "vue"
    import emitter from "@/utils/emitter"
    //数据
    let computer = ref("联想")
    let toy = ref('')
    //给emitter绑定send-toy事件
    emitter.on('send-toy',(value:any)=>{
        toy.value = value
    })
    onUnmounted(()=>{
        emitter.off('send-toy')
    })
</script>

<style scoped>
.Child{
    background-color: orange;
    width: 1000px;
    height: 200px;
}
</style>